<?php
class Search_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
	
	function keyword_tag_update($str)
	{
		$is_exist  = $this->db->from('keyword_tag')->where("keyword_tag_word LIKE '%".addslashes($str)."%'")->count_all_results();
		$datetime = date('Y-m-d H:i:s');
		if(empty($is_exist) && strlen($str) > 5):
			$data = array(
				'keyword_tag_word' => $str,
				'keyword_tag_weight' => '1',
				'is_show' => '1',
				'update_date' => $datetime
			);
			$this->db->insert('keyword_tag',$data);
		else:
			$dataKeyword = $this->db->select('keyword_tag_id')
			->get_where('keyword_tag',"keyword_tag_word LIKE '%".addslashes($str)."%'",1)
			->row();
			if(!empty($dataKeyword)) $this->db->update('keyword_tag',array('update_date' => $datetime),array('keyword_tag_id' => $dataKeyword->keyword_tag_id));
		endif;
	}	
}

?>